#!/bin/bash
tar xf coreutils-8.31.tar.xz 
cd coreutils-8.31
autoreconf -fiv
CFLAGS="$CFLAGS --sysroot=$1" FORCE_UNSAFE_CONFIGURE=1 ./configure --prefix=$1/usr --enable-no-install-program=kill,uptime --host=$4
make -j$2
make install
mv -v $1/usr/bin/{cat,chgrp,chmod,chown,cp,date,dd,df,echo} $1/bin
mv -v $1/usr/bin/{false,ln,ls,mkdir,mknod,mv,pwd,rm} $1/bin
mv -v $1/usr/bin/{rmdir,stty,sync,true,uname} $1/bin
mv -v $1/usr/bin/chroot $1/usr/sbin
mv -v $1/usr/share/man/man1/chroot.1 $1/usr/share/man/man8/chroot.8
sed -i s/\"1\"/\"8\"/1 $1/usr/share/man/man8/chroot.8
mv -v $1/usr/bin/{head,nice,sleep,touch} $1/bin
cd ..
rm -rf coreutils-8.31


